package qferror

import (
	"fmt"
)

// Error def
type Error struct {
	code int
	msg  string
}

var _codes = map[int]string{}

// NewError def
func NewError(code int, msg string) *Error {
	if _, ok := _codes[code]; ok {
		panic(fmt.Sprintf("err code:%d has already exist, please change one.", code))
	}

	_codes[code] = msg
	return &Error{code: code, msg: msg}
}

func (e *Error) Error() string {
	return fmt.Sprintf("code:%d, msg:%s", e.Code(), e.Msg())
}

// Code def
func (e *Error) Code() int {
	return e.code
}

// Msg def
func (e *Error) Msg() string {
	return e.msg
}

// Error code def
var (
	ErrOK             = NewError(0, "succeed")
	ErrNoIdleTeu      = NewError(1001, "no idle teu error")
	ErrNoClientInfo   = NewError(1002, "no client info error")
	ErrNoTeu          = NewError(1003, "no teu error")
	ErrClientNeedAuth = NewError(1004, "client haven't authorized or authorize failed")
)
